package com.computergames.server.service.getCurrentPlayerStrategy;


import com.computergames.server.message.Message;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class Play_GetCurrentPlayerStrategySelector {
    private final Map<Integer, Play_GetCurrentPlayerStrategy> strategyMap = new ConcurrentHashMap<>();

    public Play_GetCurrentPlayerStrategySelector()
    {
        strategyMap.put(Message.GobangMessage, new Play_GetChessCurrentPlayer());
        strategyMap.put(Message.LandlordMessage, new Play_GetLandlordCurrentPlayer());
    }

    public boolean select(String roomName, String from, int messageType)
    {
        Play_GetCurrentPlayerStrategy strategy = strategyMap.get(messageType);
        if (strategy == null)
        {
            throw new IllegalArgumentException("No strategy found for message type: " + messageType);
        }
        return strategy.getCurrentPlayer(roomName, from);
    }
}
